package JAVA300.第九章容器;
/**
 * 测试treeMap
 */

import java.time.chrono.IsoChronology;
import java.util.Map;
import java.util.TreeMap;

/**
 * 测试treeMap
 */

public class TestTreeMap {
    public static void main(String[] args) {
        Map<Integer,String> treemap = new TreeMap<>();
        treemap.put(20,"aa");
        treemap.put(5,"bb");
        treemap.put(30,"cc");

        for (Integer key:treemap.keySet()){
            System.out.println(key+"--"+treemap.get(key));
        }

        Map<Emp,String> treemap2 = new TreeMap<>();
        treemap2.put(new Emp(2,"hqq",167000),"hqqqq");
        treemap2.put(new Emp(1,"qyh",187800),"qhhhh");
        //treemap2.put(30,"cc");

        for (Emp key:treemap2.keySet()){
            System.out.println(key+"--"+treemap2.get(key));
        }

    }


}

class Emp implements Comparable<Emp>{
    int id;
    String name;
    double Salary;

    public Emp(int id, String name, double salary) {
        super();
        this.id = id;
        this.name = name;
        this.Salary = salary;
    }
    @Override
    public String toString() {
        return "id+"+id+"salary:"+Salary+"name:"+name;
    }

    @Override
    public int compareTo(Emp o) {//对象对比：-1：小于 0：等于 1:大于

        if (this.Salary < o.Salary){
            return -1;
        }else if (this.Salary > o.Salary){
            return 1;
        }else {
            return 0;
        }


    }
}
